﻿using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(XXX.Web.Host.Startup))]

namespace XXX.Web.Host
{
	public partial class Startup
	{
		#region Configuration

		public void Configuration(IAppBuilder app)
		{
			RegisterTypes();

			//Sidvall.Web.Host.Startup.ConfigureAuthentication(app, Properties.Settings.Default.STSBaseAddress, XXX.Security.AuthorizationManager.AuthorityUserInfoEndpoint,
			//	XXX.Security.AuthorizationManager.AuthorityTokenEndpoint, Properties.Settings.Default.BaseAddress, Properties.Settings.Default.STSClientId,
			//	Properties.Settings.Default.STSClientSecret, XXX.Security.AuthorizationManager.ResponseType, XXX.Security.AuthorizationManager.Scope,
			//	"/InvalidUser/{0}", false, XXX.SystemContext.Current.ServerContentProvider);
			ConfigureWebApi(app);
		}

		#endregion
		#region RegisterTypes

		private static void RegisterTypes()
		{
			// Framework
			var authorizationProvider = new Sidvall.Security.PublicAuthorizationProvider();
			Sidvall.SystemContext.Current = new Sidvall.SystemContext()
			{
				AuthorizationManager = new Sidvall.Security.AuthorizationManager(authorizationProvider),
				AuthenticationManager = new Sidvall.Security.AuthenticationManager(new Sidvall.Security.AuthenticationProvider()),
				//CacheManager = new Sidvall.Caching.CacheManager(new Sidvall.Caching.MemoryCache()),
				ClaimManager = new Sidvall.Security.ClaimManager(new Sidvall.Security.ClaimsPrincipalManager()),
				CodeManager = new Sidvall.Reflection.CodeManager(new Sidvall.Reflection.Code()),
				ExceptionManager = new Sidvall.ExceptionHandling.ExceptionManager(new Sidvall.ExceptionHandling.ExceptionProvider()),
				HttpClientFactory = new Sidvall.Net.HttpClientFactory(),
				//LogManager = new Sidvall.Logging.LogManager(new Sidvall.Logging.EL.Log()),
				SmtpClientManager = new Sidvall.Net.Mail.SmtpClientManager(new Sidvall.Net.Mail.SmtpClient()),
				//SmsClientManager = new Sidvall.Net.Sms.SmsClientManager(new Sidvall.Net.Sms.SmsClient()),
				//SoapClientFactory = new Sidvall.Net.SoapClientFactory(),
				SystemStorageManager = new Sidvall.IO.StorageManager(new Sidvall.IO.FileSystem()),
				TransactionScopeFactory = new Sidvall.Data.TransactionScopeFactory(),
				TypeCache = new Sidvall.Reflection.TypeCache(),
				UserManager = new Sidvall.Security.UserManager(authorizationProvider),
				//UserStorageManager = new Sidvall.IO.StorageManager(new Sidvall.IO.Storage.LocalStorage()),

				// Client
				//PrincipalContextManager = new Sidvall.Security.PrincipalContextManager(new Sidvall.Security.PrincipalContextProvider()),
				//PrincipalManager = new Sidvall.Security.PrincipalManager(new Sidvall.Security.PrincipalProvider()),

				// Server
				PrincipalContextManager = new Sidvall.Security.PrincipalContextManager(new Sidvall.Web.Security.PrincipalContextProvider()),
				PrincipalManager = new Sidvall.Security.PrincipalManager(new Sidvall.Web.Security.PrincipalProvider()),

				// Host specific
				ResourceManager = new Sidvall.Resources.ResourceManager(new XXX.Web.Host.Resources.ResourceManager()),
				SettingsManager = new Sidvall.Configuration.SettingsManager(new XXX.Web.Host.Configuration.ApplicationSettings()),
			};
			//Sidvall.Data.Sqlite.SystemContext.Current = new Sidvall.Data.Sqlite.SystemContext()
			//{
			//	SQLitePlatform = new SQLite.Net.Platform.Win32.SQLitePlatformWin32(),
			//};
			//Sidvall.Office.SystemContext.Current = new Sidvall.Office.SystemContext()
			//{
			//	//ExcelManager = new Sidvall.Office.ExcelManager(new Sidvall.Office.Excel()),
			//};
			//Sidvall.Reporting.SystemContext.Current = new Sidvall.Reporting.SystemContext()
			//{
			//	//ReportManager = new Sidvall.Reporting.ReportManager(new Sidvall.Reporting.Report()),
			//};

			// Application specific
			//XXX.SystemContext.Current.DataPortalStrategy = new Sidvall.DataPortal.DataPortalStrategy()
			//{
			//	MasterServerConnection = Sidvall.DataPortal.ServerConnectionManager.GetSqlServerConnection(new XXX.Data.Entity.Model.StorageManagerFactory()),
			//};
		}

		#endregion
	}
}